package com.xiebishe.mylibrary.net.retrofit.bean;

import com.alibaba.fastjson.annotation.JSONField;
import com.xiebishe.mylibrary.net.retrofit.ExceptionHandle;


/**
 * @class NetBaseBean
 * @describe response的基本结构
 */
public class NetBaseBean<T> {

    @JSONField(name = "code")
    private int code;

    @JSONField(name = "msg")
    private String message;

    @JSONField(name = "data")
    private T data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        if (isOk())
            return data;
        else throw new ExceptionHandle.CustomException(code, message);
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isOk() {
        return code == 0;
    }
}
